# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=libxml2
pkgver=2.13.4
pkgrel=3
pkgdesc="XML parsing library, version 2"
url="https://gitlab.gnome.org/GNOME/libxml2"
arch="all"
license="MIT"
depends_dev="zlib-dev xz-dev $pkgname-utils=$pkgver-r$pkgrel"
checkdepends="perl tar"
makedepends_host="$depends_dev"
subpackages="$pkgname-dbg $pkgname-doc $pkgname-static $pkgname-dev $pkgname-utils"
if [ -z "$BOOTSTRAP" ]; then
	makedepends_build="$makedepends_build python3-dev"
	subpackages="$subpackages py3-$pkgname-pyc py3-$pkgname:_py3"
	_py_configure="--with-python=/usr/bin/python3"
else
	_py_configure="--with-python=no"
fi
source="https://download.gnome.org/sources/libxml2/${pkgver%.*}/libxml2-$pkgver.tar.xz
	0001-parser-Fix-downstream-code-that-swaps-DTDs.patch
	"

# secfixes:
#   2.12.7-r0:
#     - CVE-2024-34459
#   2.12.5-r0:
#     - CVE-2024-25062
#   2.10.4-r0:
#     - CVE-2023-28484
#     - CVE-2023-29469
#   2.10.3-r0:
#     - CVE-2022-40303
#     - CVE-2022-40304
#   2.10.0-r0:
#     - CVE-2022-2309
#   2.9.14-r0:
#     - CVE-2022-29824
#   2.9.13-r0:
#     - CVE-2022-23308
#   2.9.11-r0:
#     - CVE-2016-3709
#     - CVE-2021-3517
#     - CVE-2021-3518
#     - CVE-2021-3537
#     - CVE-2021-3541
#   2.9.10-r5:
#     - CVE-2020-24977
#   2.9.10-r4:
#     - CVE-2019-20388
#   2.9.8-r3:
#     - CVE-2020-7595
#   2.9.8-r1:
#     - CVE-2018-9251
#     - CVE-2018-14404
#     - CVE-2018-14567
#   2.9.4-r4:
#     - CVE-2017-5969
#   2.9.4-r2:
#     - CVE-2016-9318
#   2.9.4-r1:
#     - CVE-2016-5131

prepare() {
	default_prepare

	# We don't build libxml2 with icu.
	rm test/icu_parse_test.xml
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-static \
		--with-legacy \
		--with-lzma \
		--with-zlib \
		$_py_configure
	make
}

check() {
	rm -f test/ebcdic_566012.xml
	make runtests
}

package() {
	make -j1 DESTDIR="$pkgdir" install
}

_py3() {
	depends="python3"
	pkgdesc="$pkgname python3 bindings"

	amove usr/lib/python3*
}

utils() {
	pkgdesc="XML utilities"
	replaces="libxml2"

	amove usr/bin
}

sha512sums="
27bfaa63431798d3aa725b36af2005bda70a20b270e601cc3c8a07cc9fd02a080cb3d2b023eb42606a57b9786469488a7c09b71bdff1a518a0b4271c78c3f940  libxml2-2.13.4.tar.xz
e7f1cd7f961647084c8b8bd1e1ab35389e74cd66d0125413181261ce0d83a51ea2d617e4fc77d6645b252e9e3710c8fd0df2bd13ede7d4ed7b3eec64feeea4c9  0001-parser-Fix-downstream-code-that-swaps-DTDs.patch
"
